package com.example.coffeeseller_2.model.contentprovider;

import android.text.TextUtils;

import com.example.coffeeseller_2.model.beans.BitmapCacheBean;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by WH on 2018/6/15.
 */

public class ApplicationConstance {


    private static ApplicationConstance instance;

    private boolean hasCoffeeSelected = false;
    private long lastClearMachineTime = 0;
    private boolean isClearTimeSeted = true;//清洗时间是否已经显示
    private boolean isPayed = false;
    private String curErrCode = ""; //取杯超时错误码等额外非机器状态的错误码
    private String lastErrCode = "";
    private boolean isBeanEnough = true;

    private Map<String, BitmapCacheBean> bitmapCacheBeanMap = new HashMap<>();

    public static ApplicationConstance getInstance() {
        if (instance == null) {
            instance = new ApplicationConstance();
        }
        return instance;
    }


    public ApplicationConstance() {
    }

    /*
    * 取得错误码
    * */
    public String getErrorCode() {

        if (TextUtils.equals(curErrCode, lastErrCode)) {
            lastErrCode = "";
            curErrCode = "";
            return null;
        } else if (TextUtils.isEmpty(curErrCode)) {
            return null;
        } else {
            lastErrCode = curErrCode;
            curErrCode = "";
            return lastErrCode;
        }
    }

    public String getCurErrCode() {
        return curErrCode;
    }

    public void setCurErrCode(String curErrCode) {
        this.curErrCode = curErrCode;
    }

    public String getLastErrCode() {
        return lastErrCode;
    }

    public void setLastErrCode(String lastErrCode) {
        this.lastErrCode = lastErrCode;
    }

    public boolean isHasCoffeeSelected() {
        return hasCoffeeSelected;
    }

    public void setHasCoffeeSelected(boolean hasCoffeeSelected) {
        this.hasCoffeeSelected = hasCoffeeSelected;
    }

    public long getLastClearMachineTime() {
        return lastClearMachineTime;
    }

    public void setLastClearMachineTime(long lastClearMachineTime) {
        this.lastClearMachineTime = lastClearMachineTime;
        setClearTimeSeted(false);
    }

    public boolean isClearTimeSeted() {
        return isClearTimeSeted;
    }

    public void setClearTimeSeted(boolean clearTimeSeted) {
        isClearTimeSeted = clearTimeSeted;
    }

    public boolean isPayed() {
        return isPayed;
    }

    public void setPayed(boolean payed) {
        isPayed = payed;
    }

    public Map<String, BitmapCacheBean> getBitmapCacheBeanMap() {
        return bitmapCacheBeanMap;
    }

    public void setBitmapCacheBeanMap(Map<String, BitmapCacheBean> bitmapCacheBeanMap) {
        this.bitmapCacheBeanMap = bitmapCacheBeanMap;
    }

    public boolean isBeanEnough() {
        return isBeanEnough;
    }

    public void setBeanEnough(boolean beanEnough) {
        isBeanEnough = beanEnough;
    }
}
